<template>
  <div class="order">
    <div class="headerhh">
      <div @click="goBack" style="float: left">
        <a-icon type="left" class="icon" />
        <a class="h3">体征采集</a>
      </div>
    </div>
    <div class="screen">
      <div class="screen-left comm-screen">
        <span class="f-left">选择时间</span>
        <div class="f-right">
          <a-range-picker
            @change="onChange"
            @openChange="openChange"
            :allowClear="true"
            :placeholder="['开始时间', '结束时间']"
          />
        </div>
      </div>
      <div class="screen-right comm-screen">
        <span class="f-left">体征记录</span>
        <span class="f-right" @click="handleSubmit" id="select">{{selectName}}</span>
      </div>
      <transition>
        <div class="pull-down" v-show="showDown">
          <ul class="pull-ul">
            <li
              v-for="(item,index) in downdata"
              :key="index"
              @click="itemclick(item.id,item.transferTimePoint)"
            >{{item.transferTimePoint}}</li>
          </ul>
        </div>
      </transition>
      <!-- <transition>
        <div class="pull-down" v-if="showDownflag">
          <ul class="pull-ul">暂无数据！</ul>
        </div>
      </transition>-->
    </div>
    <div class="sign-content">
      <div class="sign-one sign-base">
        <div class="animalheat">
          <p>体温</p>
          <p>单位：℃</p>
        </div>
        <p class="particulars" v-if="data.temperature">{{data.temperature}}</p>
        <p class="particulars" v-else>--</p>
      </div>
      <div class="sign-two sign-base">
        <div class="animalheat">
          <p>脉搏</p>
          <p>单位：次/分</p>
        </div>
        <p class="particulars" v-if="data.pulse">{{data.pulse}}</p>
        <p class="particulars" v-else>--</p>
      </div>
      <div class="sign-three sign-base">
        <div class="animalheat">
          <p>呼吸</p>
          <p>单位：次/分</p>
        </div>
        <p class="particulars" v-if="data.respiration_value">{{data.respiration_value}}</p>
        <p class="particulars" v-else>--</p>
      </div>
      <div class="sign-four sign-base">
        <div class="animalheat">
          <p>血压</p>
          <p>单位：mmHg</p>
        </div>
        <div class="shrink">
          <div>
            <p>收缩压:</p>
            <p v-if="data.sdp">{{data.sdp}}</p>
            <p v-else>-</p>
          </div>
          <div>
            <p>舒张压:</p>
            <p v-if="data.dbp">{{data.dbp}}</p>
            <p v-else>-</p>
          </div>
        </div>
      </div>
    </div>
    <div class="layder" v-if="showflag">
      <div class="lay-cont">
        <div class="stateimg">
          <img src="../../../static/images/indexone/state03.png" />
        </div>
        <p>请先选择时间!</p>
      </div>
    </div>
    <div class="showload" v-show="showimg">
      <div class="showbox">
        <img src="../../../static/images/sign/timg.png" alt class="showimg" />
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import urls from '../../common.js'
// import $ from 'jquery'
export default {
  name: 'index',
  data () {
    return {
      pa_id: this.$store.state.personinfo.pa_id, // pa_id
      data: [],
      showDown: false, // 下拉框
      showflag: false, // 弹出层选择时间
      downdata: [],
      startTime: '', // 开始时间
      endTime: '', // 结束时间
      selectName: '请选择',
      showimg: false // 弹出层正在加载
    }
  },
  created () {
    this.postQuerySignByPaId() // 根据paid查询接口
  },
  mounted () {
    document.addEventListener('click', e => { // 除了id为select的点击，下拉框都隐藏
      if (e.target.id !== 'select') {
        this.showDown = false
      }
    })
  },
  methods: {
    moment,
    goBack () {
      this.$router.go(-1) // 返回上一页
    },
    openChange () { // 当日期发生改变
      this.selectName = '请选择'
      this.showimg = false // 弹出层正在加载隐藏
      // this.downdata = []
    },
    postQuerySignByPaId () {
      // 根据paid查询
      const Qs = require('qs')
      var _this = this
      this.$http
        .post(urls.postQuerySignByPaId, Qs.stringify({ paId: this.pa_id }), {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
          }
        })
        .then(result => {
          if (result.body.code === '200') {
            _this.data = result.body.data
          }
        })
    },
    onChange (date, dateString) {
      // 选择时间
      this.showimg = true // 弹出层正在加载显示
      this.selectName = '请选择'
      this.startTime = dateString[0] ? dateString[0] + ' 00:00:00' : ''
      this.endTime = dateString[1] ? dateString[1] + ' 00:00:00' : ''
      let formObj = {
        startdate: this.startTime,
        enddate: this.endTime,
        paId: this.pa_id
      }
      this.$http
        .post(urls.querySignByPaIdAndTime, formObj, { emulateJSON: true }) // emulateJSON: true 解决form表单提交问题
        .then(result => {
          if (result.body.code === '200') {
            this.downdata = result.body.data
            console.log(this.downdata)
            this.showimg = false
          }
        })
      if (!dateString[0] && !dateString[1]) {
        this.startTime = ''
        this.endTime = ''
        // this.selectName = '请选择'
        this.showDown = false
        this.showimg = false
      }
    },
    handleSubmit (event) { // 点击请选择时
      event.preventDefault()
      if (!this.startTime || !this.endTime) { // 如果么有选择时间提示请选择时间
        this.showflag = true
        setTimeout(() => {
          this.showflag = false
        }, 3000)
      } else { // 否则就显示隐藏下拉框
        // this.showimg = true
        this.showDown = !this.showDown
      }
    },
    itemclick (id, idname) { // 点击每一条显示不同的数据
      // 点击每一项调接口
      const Qs = require('qs')
      var _this = this
      this.$http
        .post(urls.querySignById, Qs.stringify({ id: id }), {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
          }
        })
        .then(result => {
          if (result.body.code === '200') {
            // console.log(result.body.data)
            _this.data = result.body.data
          }
        })
      this.showDown = false // 下拉框隐藏
      this.selectName = idname // 把每一项赋值给标题
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '../../../static/css/color.styl';

.headerhh {
  height: 0.98rem;
  background-color: $color-main;
  text-align: justify;
  line-height: 0.98rem;
  padding-left: 0.3rem;
  color: $color-white;
  margin-bottom: 0.5rem;

  .icon {
    font-size: 0.36rem;
    color: $color-white;
    vertical-align: -0.07rem;
  }

  .h3 {
    display: inline-block;
    font-size: 0.36rem;
    color: $color-white;
  }
}

.screen {
  position: relative;
  width: 14.36rem;
  height: 0.8rem;
  line-height: 0.8rem;
  display: flex;
  justify-content: space-around;
  margin: auto;
  margin-bottom: 0.5rem;

  .comm-screen {
    height: 100%;
    background-color: #fff;
    border-radius: 0.2rem;
    box-shadow: #ccc 0px 1px 1px -1px; // 底部阴影
    padding: 0 0.3rem;

    span {
      &:nth-of-type(1) {
        color: $color-main;
      }

      &:nth-of-type(2) {
        color: $color-gray;
      }
    }

    #select {
      display: inline-block;
      width: 4rem;
      text-align: right;
    }
  }

  .screen-left {
    width: 7.7rem;
  }

  .screen-right {
    width: 6.4rem;
  }

  .pull-down {
    width: 6.4rem;
    height: 3rem;
    background-color: rgba(255, 255, 255, 0.7);
    position: absolute;
    top: 0.9rem;
    right: 0.1rem;
    border-radius: 0.2rem;
    box-shadow: #ccc 0px 1px 1px -1px;
    padding: 0 0.3rem;

    .pull-ul {
      width: 6.1rem;
      height: 3rem;
      max-height: 3rem;
      overflow-y: auto;

      li {
        font-size: 0.28rem;
        color: #1a1a1a;
        height: 0.6rem;
      }
    }
  }
}

.sign-content {
  width: 14.36rem;
  height: 6.44rem;
  display: flex;
  justify-content: space-around;
  margin: auto;
  flex-wrap: wrap;

  .sign-base {
    width: 6.96rem;
    height: 3.03rem;
    border-radius: 0.2rem;
    padding: 0.3rem;
  }

  .sign-one {
    background-image: url('../../../static/images/sign/signOne.png');
  }

  .sign-two {
    background-image: url('../../../static/images/sign/signTwo.png');
  }

  .sign-three {
    background-image: url('../../../static/images/sign/signOne.png');
  }

  .sign-four {
    background-image: url('../../../static/images/sign/signThree.png');
  }

  .animalheat {
    height: 0.3rem;
    border-left: 4px solid #fff;
    padding: 0 0.15rem 0 0.15rem;
    display: flex;
    justify-content: space-between;

    p {
      font-size: 0.3rem;
      color: #fff;
    }
  }

  .particulars {
    font-size: 1.2rem;
    text-align: center;
    color: #fff;
    line-height: 2.5rem;
  }

  .shrink {
    width: 3.9rem;
    height: 1.35rem;
    display: flex;
    justify-content: space-around;
    margin: 0.56rem auto;
    text-align: center;

    p {
      color: #fff;

      &:nth-of-type(1) {
        font-size: 0.3rem;
        margin-bottom: 0.4rem;
      }

      &:nth-of-type(2) {
        font-size: 0.8rem;
      }
    }
  }
}

.ant-dropdown {
  position: relative;

  ul {
    position: absolute;
    right: -0.28rem;
    top: 0.3rem;
    width: 6.4rem;
    height: 1.6rem;
    border-radius: 0.2rem;
  }
}

.ant-dropdown-link {
  color: $color-gray;
}

.ant-dropdown-menu-item {
  font-size: 0.28rem;
  color: #1a1a1a;
}

.v-enter {
  opacity: 0;
  transform: translateY(-20px);
}

.v-leave-to {
  opacity: 0;
  transform: translateY(20px);
}

.v-enter-active, .v-leave-active {
  transition: all 0.4s ease;
}

.layder {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;

  .lay-cont {
    width: 4rem;
    height: 2.3rem;
    background-color: rgba(0, 0, 0, 0.6);
    margin: 4.8rem auto;
    border-radius: 0.3rem;
    color: #fff;
    text-align: center;
    padding-top: 0.4rem;
    font-size: 0.32rem;

    .stateimg {
      width: 0.78rem;
      height: 0.78rem;
      margin: 0 auto 0.4rem auto;

      img {
        width: 100%;
        height: 100%;
        display: block;
      }
    }
  }
}

.showload {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;

  .showbox {
    width: 4rem;
    height: 2.3rem;
    // background-color: rgba(0, 0, 0,0.5);
    // background-color: #fafafa;
    margin: 3.6rem auto;
    border-radius: 0.3rem;
    color: #fff;
    text-align: center;
    font-size: 0.32rem;

    .showimg {
      // width: 0.8rem;
      // height: 0.8rem;
      // width: 100%;
      height: 100%;
      display: inline-block;
      // margin-top: 0.7rem;
    }
  }
}
</style>
